package com.gc.gc.duty.control;

import com.gc.gc.common.control.BaseController;
import com.gc.gc.duty.entity.DutyServiceEnity;
import com.gc.gc.duty.service.DutyService;
import com.gc.gc.mybatis.entity.PtDutyEntity;
import com.gc.gc.mybatis.flexigrid.PadingRstType;
import com.gc.gc.mybatis.flexigrid.PagingBean;
import com.gc.gc.mybatis.ztree.ZtreeEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/duty")
public class DutyController extends BaseController {
    private Logger logger =  LogManager.getLogger(this.getClass().getName());
    @Resource
    private DutyService dutyService;
    @Secured("ROLE_gqgy_data_post")
    @RequestMapping("/dutyPage")
    public String dutyPage(){
        return "duty/dutyPage";
    }

    @RequestMapping("/getDutyInfolistByPage")
    @ResponseBody
    public PadingRstType<PtDutyEntity> getDutyInfolistByPage(DutyServiceEnity search, PagingBean paging){
        logger.info(search);
        PadingRstType<PtDutyEntity> ptDutyEntityPadingRstType = dutyService.getDutyInfolistByPage(search,paging);
        return ptDutyEntityPadingRstType;
    }

    @RequestMapping("/ptDuty/getDutyZtreeList")
    @ResponseBody
    public PadingRstType<PtDutyEntity> getDutyZtreeList(DutyServiceEnity search, PagingBean paging){
        logger.info(search);
        PadingRstType<PtDutyEntity> ptDutyEntityPadingRstType = dutyService.getDutyInfolistByPage(search,paging);
        return ptDutyEntityPadingRstType;
    }
    @RequestMapping("/deleteDutyById")
    @ResponseBody
    public String deleteDutyById(@RequestParam("dutyid") String dutyid){
        logger.info("dutyid:" + dutyid);
        dutyService.deleteDutyById(dutyid);
        return getSuccessMsg("duty.delete.success");
    }

    @RequestMapping("/addDuty")
    @ResponseBody
    public String addDuty(@RequestParam("dutyName") String dutyName){
        DutyServiceEnity search=new DutyServiceEnity();
        search.setDutyName(dutyName);
        logger.info("add:"+search);
        dutyService.addDuty(search);
        return getSuccessMsg("duty.add.success");
    }


}
